package com.ocm.tourism.core.service;

import com.ocm.tourism.core.dao.CommonItemsDao;
import com.ocm.tourism.core.domain.CommonItems;
import com.ocm.tourism.core.domain.ItemTypes;

import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service
@Transactional
public class CommonItemsServiceImpl implements CommonItemsService {

   @Autowired
   CommonItemsDao commonItemsDao;

   public long countAllCommonItemses() {
      return commonItemsDao.count();
   }

   public void deleteCommonItems(CommonItems commonItems) {
      commonItemsDao.remove(commonItems.getId());
   }

   public CommonItems findCommonItems(Long id) {
      return commonItemsDao.find(id);
   }

   public List<CommonItems> findAllCommonItemses() {
      return commonItemsDao.findAll();
   }

   public List<CommonItems> findCommonItemsEntries(int firstResult, int maxResults) {
      return commonItemsDao.findAll(firstResult, maxResults);
   }

   public void saveCommonItems(CommonItems commonItems) {
      if (commonItems.getId() == null || commonItems.getId() == 0)
         commonItemsDao.save(commonItems);
      else
         commonItemsDao.update(commonItems);
   }

   public CommonItems updateCommonItems(CommonItems commonItems) {
      return commonItemsDao.update(commonItems);
   }

   @Override
   public List<CommonItems> findAllCountrys() {
      List<CommonItems> commonItems = this.commonItemsDao.findByType(ItemTypes.COUNTRY);
      return commonItems;
   }

   @Override
   public List<CommonItems> findAllCitys() {
      List<CommonItems> commonItems = this.commonItemsDao.findByType(ItemTypes.CITY);
      return commonItems;
   }

   @Override
   public List<CommonItems> findAllConcurrencies() {
      List<CommonItems> commonItems = this.commonItemsDao.findByType(ItemTypes.CONCURRENCY);
      return commonItems;
   }

   @Override
   public List<CommonItems> findAllTransports() {
      List<CommonItems> commonItems = this.commonItemsDao.findByType(ItemTypes.TRANSPORT);
      return commonItems;
   }
}
